package cn.wgoodq.study.MultiThreading.exercise.entity;

/**
 * Created by OuKyou on 2017/1/21.
 */
public class Printer {
    private boolean flag = true;

    public synchronized int printFigure(int i) throws InterruptedException {
        if (!flag) {
            wait();
        }
        System.out.println(i);
        i = i + 1;
        System.out.println(i);
        flag = false;
        notifyAll();
        return i;
    }

    public synchronized void printCharacter(int i) throws InterruptedException {
        if (flag) {
            wait();
        }
        System.out.println((char) i);
        flag = true;
        notifyAll();
    }
}
